{% set template = haproxy_template.s4b %}
# Defaults for {{ name }}
defaults {{ name }}
	# Set proxy type
	mode http

	# Retry another server on connection failure
	option redispatch

	# Timeouts
	timeout connect            5s
	timeout http-keep-alive    1s
	timeout http-request       15s
	timeout queue              30s
	timeout tarpit             1m
	timeout client             300s
	timeout server             300s

	# Logging options
	option httplog
	option dontlognull
	log global

	# Set balance mode
	balance roundrobin

	# Default server check options
{% if proxy.defaults is defined %}
	default-server inter {{ proxy.defaults.interval|default(template.interval) }} rise {{ proxy.defaults.rise|default(template.rise) }} fall {{ proxy.defaults.fall|default(template.fall) }}
{% else %}
	default-server inter {{ template.interval }} rise {{ template.rise }} fall {{ template.fall }}
{% endif %}

# Front-End for {{ name }}
frontend fe_{{ name }}
	# Listen on 80 and 443
{% for bind in proxy.frontend.bind %}
	bind {{ bind.ip }}:443 ssl crt {{ bind.crt }}
	bind {{ bind.ip }}:80
{% endfor %}

	# Use specific back-end
	use_backend be_{{ name }}_ssl if ssl_fc
	use_backend be_{{ name }}

# Back-End for {{ name }} (SSL)
backend be_{{ name }}_ssl
	# Health check options
	option tcp-check
	option log-health-checks

	# S4B servers
{% for server in proxy.backend.server %}
	server {{ server.name }} {{ server.ip }}:4443 ssl check port 5061 ca-file {{ server.ca_file }}
{% endfor %}


# Back-End for {{ name }}
backend be_{{ name }}
# Health check options
	option tcp-check
	option log-health-checks

	# S4B servers
{% for server in proxy.backend.server %}
	server {{ server.name }} {{ server.ip }}:8080 check port 5061
{% endfor %}
